import pandas as pd
import numpy as np


def load_data1():
    # 读取数据
    df = pd.read_csv("c:/Users/16028/Desktop/mcm/2023c/proj/data/1.csv")
    dtype = [
        ("product_code", "U20"),  # 单品编码
        ("product_name", "U20"),  # 单品名称
        ("category_code", "U20"),  # 分类编码
        ("category_name", "U20"),  # 分类名称
    ]
    structured_array = np.array([tuple(row) for row in df.to_numpy()], dtype=dtype)
    # print(structured_array[:10])
    return structured_array


def load_data2():
    df = pd.read_csv("c:/Users/16028/Desktop/mcm/2023c/proj/data/2.csv")
    dtype = [
        ("sale_date", "U10"),  # 销售日期
        ("scan_time", "U12"),  # 扫码销售时间
        ("product_code", "U20"),  # 单品编码
        ("quantity", "f8"),  # 销量(千克)
        ("unit_price", "f8"),  # 销售单价(元/千克)
        ("sale_type", "U10"),  # 销售类型
        ("is_discounted", "U10"),  # 是否打折销售
    ]
    structured_array = np.array([tuple(row) for row in df.to_numpy()], dtype=dtype)
    # print(structured_array[:10])
    return structured_array


def load_data3():
    df = pd.read_csv("c:/Users/16028/Desktop/mcm/2023c/proj/data/3.csv")
    dtype = [
        ("date", "U10"),  # 日期
        ("product_code", "U20"),  # 单品编码
        ("wholesale_price", "f8"),  # 批发价格(元/千克)
    ]
    structured_array = np.array([tuple(row) for row in df.to_numpy()], dtype=dtype)
    # print(structured_array[:10])
    return structured_array


def load_data4():
    df = pd.read_csv("c:/Users/16028/Desktop/mcm/2023c/proj/data/4.csv")
    dtype = [
        ("category_code", "U10"),  # 小分类编码
        ("category_name", "U20"),  # 小分类名称
        ("loss_rate", "f8"),  # 平均损耗率(%)
    ]
    structured_array = np.array([tuple(row) for row in df.to_numpy()], dtype=dtype)
    # print(structured_array[:10])
    return structured_array


def transfer_to_csv():
    df = pd.read_excel("c:/Users/16028/Desktop/mcm/2023c/proj/data/4.xlsx")
    df.to_csv("c:/Users/16028/Desktop/mcm/2023c/proj/data/4.csv", index=False)
    print("finish")


if __name__ == "__main__":
    load_data4()
